package org.nggen.config;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import com.jfinal.log.Logger;

public class IOKit {
	private static final Logger logger = Logger.getLogger(IOKit.class);

	public static String readToString(File file){
		StringBuffer text = new StringBuffer();
		FileReader fr = null;
		BufferedReader br = null;
		try {
			fr = new FileReader(file);
			br = new BufferedReader(fr);
			String txt = null;
			while ((txt = br.readLine()) != null){
				text.append(txt).append("\r\n");
			}
		} catch (FileNotFoundException e) {
			logger.error(e.getMessage(), e);
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
		}finally  {
			if(br != null){
				try {
					br.close();
				} catch (IOException e) {
					logger.error(e.getMessage(), e);
				}
			}
			
			if(fr != null){
				try {
					fr.close();
				}catch(IOException e){
					logger.error(e.getMessage(), e);
				}
			}
		}
		
		return text.toString();
	}
}
